<template>
  <div class="dashboard-container">
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <el-icon class="card-panel-icon"><Menu /></el-icon>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">试卷总数</div>
            <div class="card-panel-num">{{ numdata.examPaperCount }}</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-message">
            <el-icon class="card-panel-icon"><Document /></el-icon>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">题目总数</div>
            <div class="card-panel-num">{{ numdata.questionCount }}</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <el-icon class="card-panel-icon"><DocumentChecked /></el-icon>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">答卷总数</div>
            <div class="card-panel-num">{{ numdata.doQuestionCount }}</div>
            <div class="card-panel-num"></div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <el-icon class="card-panel-icon"><EditPen /></el-icon>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">答题总数</div>
            <div class="card-panel-num">{{ numdata.doExamPaperCount }}</div>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row class="echarts-line">
      <v-chart
        class="chart"
        :option="option1"
        style="width: 100%; height: 800px"
      />
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { getdashboarddata } from '@/api/dashboard.js'
const numdata = ref({})
const getdash = async () => {
  const res = await getdashboarddata()
  numdata.value = res.data.data
}
getdash()
const data = [
  ['2021-06', 11, 202],
  ['2021-07', 116, 212],
  ['2021-08', 92, 121],
  ['2021-09', 96, 312],
  ['2021-10', 116, 143],
  ['2021-11', 139, 154],
  ['2021-12', 133, 156],
  ['2022-01', 188, 188],
  ['2022-02', 189, 198],
  ['2022-03', 216, 120],
  ['2022-04', 326, 178],
  ['2022-05', 106, 231],
  ['2022-06', 116, 241],
  ['2022-07', 286, 267],
  ['2022-08', 216, 287]
]
const dateList = data.map(function (item) {
  return item[0]
})
const valueList = data.map(function (item) {
  return item[1]
})
const dateList1 = data.map(function (item) {
  return item[0]
})
const valueList1 = data.map(function (item) {
  return item[2]
})
const option1 = ref({
  // Make gradient line here
  visualMap: [
    {
      show: false,
      type: 'continuous',
      seriesIndex: 0,
      min: 0,
      max: 400
    },
    {
      show: false,
      type: 'continuous',
      seriesIndex: 1,
      dimension: 0,
      min: 0,
      max: dateList1.length - 1
    }
  ],
  title: [
    {
      left: 'center',
      text: '用户活跃度'
    },
    {
      top: '55%',
      left: 'center',
      text: '题目月数量'
    }
  ],
  tooltip: {
    trigger: 'axis'
  },
  xAxis: [
    {
      data: dateList
    },
    {
      data: dateList1,
      gridIndex: 1
    }
  ],
  yAxis: [
    {},
    {
      gridIndex: 1
    }
  ],
  grid: [
    {
      bottom: '60%'
    },
    {
      top: '60%'
    }
  ],
  series: [
    {
      type: 'line',
      showSymbol: false,
      data: valueList
    },
    {
      type: 'line',
      showSymbol: false,
      data: valueList1,
      xAxisIndex: 1,
      yAxisIndex: 1
    }
  ]
})
</script>

<style lang="scss" scoped>
.dashboard-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}

.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      width: 100%;
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

.echarts-line {
  background: #fff;
  padding: 16px 16px 0;
  margin-bottom: 32px;
}
</style>
